package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;

import java.util.Timer;
import java.util.TimerTask;

public class frame extends AppCompatActivity {
    private Button back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frame);
        back = (Button) findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(frame.this, MainActivity.class);
                startActivity(intent);
            }
        });
        final ImageView i1 = findViewById(R.id.imageView);
        final ImageView i2 = findViewById(R.id.imageView2);
        final ImageView i3 = findViewById(R.id.imageView3);
        final ImageView i4 = findViewById(R.id.imageView4);
        final ImageView i5 = findViewById(R.id.imageView5);
        FrameLayout frame = findViewById(R.id.frame);
        Timer timer = new Timer();
        final Handler handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case 1:

                        i1.setVisibility(View.VISIBLE);
                        break;
                    case 2:

                        i1.setVisibility(View.INVISIBLE);
                        break;
                    case 3:

                        i2.setVisibility(View.VISIBLE);
                        break;
                    case 4:

                        i2.setVisibility(View.INVISIBLE);
                        break;
                    case 5:

                        i3.setVisibility(View.VISIBLE);
                        break;
                    case 6:

                        i3.setVisibility(View.INVISIBLE);
                        break;
                    case 7:

                        i4.setVisibility(View.VISIBLE);
                        break;
                    case 8:

                        i4.setVisibility(View.INVISIBLE);
                        break;
                    case 9:

                        i5.setVisibility(View.VISIBLE);
                        break;
                    case 10:

                        i5.setVisibility(View.INVISIBLE);
                        break;
                }
            }
        };
        timer.scheduleAtFixedRate(new TimerTask() {
            int i = 0;

            @Override
            public void run() {
                i++;
                Message msg = new Message();
                msg.what = i;
                i %= 10;
                handler.sendMessage(msg);
            }

        }, 100, 200);
    }
}
